﻿// CWndEditMContext.cpp: 实现文件
//

#include "pch.h"
#include "GameHacker.h"
#include "CWndEditMContext.h"
#include "afxdialogex.h"
#include "CMemContext.h"


// CWndEditMContext 对话框

IMPLEMENT_DYNAMIC(CWndEditMContext, CDialogEx)

CWndEditMContext::CWndEditMContext(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG1, pParent)
	, sAddress(_T(""))
	, sOffset(_T(""))
	, sNote(_T(""))
	, sData(_T(""))
{

}

CWndEditMContext::~CWndEditMContext()
{
}

void CWndEditMContext::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, sAddress);
	DDX_Text(pDX, IDC_EDIT2, sOffset);
	DDX_Control(pDX, IDC_COMBO1, m_lstType);
	DDX_Text(pDX, IDC_EDIT10, sName);
	DDX_Text(pDX, IDC_EDIT11, wCount);
	DDX_Text(pDX, IDC_EDIT12, sNote);
	DDX_Text(pDX, IDC_EDIT5, sData);
}


BEGIN_MESSAGE_MAP(CWndEditMContext, CDialogEx)
	ON_BN_CLICKED(ID_CREATE, &CWndEditMContext::OnBnClickedCreate)
	ON_BN_CLICKED(IDCANCEL, &CWndEditMContext::OnBnClickedCancel)
END_MESSAGE_MAP()


// CWndEditMContext 消息处理程序

extern DATA_TYPE data_type[12];

BOOL CWndEditMContext::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	for (auto& x : data_type) {
		m_lstType.AddString(x.sName);
	}
	m_lstType.SetCurSel(type_id);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

bool CWndEditMContext::NoEdit()
{
	//先保存之前的信息
	CString _sName = sName;
	unsigned _wCount = wCount;
	CString _sNote = sNote;
	int _type_id = type_id;
	UpdateData(TRUE);
	type_id = m_lstType.GetCurSel();
	return (_sName == sName) && (_wCount == wCount) && (_sNote == sNote) && (_type_id == type_id);
}


void CWndEditMContext::OnBnClickedCreate()
{
	if (NoEdit()) return CDialogEx::OnCancel();
	CDialogEx::OnOK();
}


void CWndEditMContext::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnCancel();
}

